<?php

/**
 * cursos actions.
 *
 * @package    ecampus
 * @subpackage cursos
 * @author     Grupo 608
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class cursosActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->cursos = Doctrine::getTable('Curso')
      ->createQuery('a')
      ->execute(); 
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new CursoForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new CursoForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($curso = Doctrine::getTable('Curso')->find(array($request->getParameter('id_curso'))), sprintf('Object curso does not exist (%s).', $request->getParameter('id_curso')));
    $this->form = new CursoForm($curso);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($curso = Doctrine::getTable('Curso')->find(array($request->getParameter('id_curso'))), sprintf('Object curso does not exist (%s).', $request->getParameter('id_curso')));
    $this->form = new CursoForm($curso);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($curso = Doctrine::getTable('Curso')->find(array($request->getParameter('id_curso'))), sprintf('Object curso does not exist (%s).', $request->getParameter('id_curso')));
    $curso->delete();

    $this->redirect('cursos/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $curso = $form->save();

      $this->redirect('cursos/edit?id_curso='.$curso->getIdCurso());
    }
  }
  public function executeGestionar(sfWebRequest $request)
  {
      $this->redirect('gestionarcurso/index?id_curso='.$request->getParameter('id_curso'));
//    $this->curso = Doctrine_Core::getTable('Curso')->find(array($request->getParameter('id_curso')));
//    $this->forward404Unless($this->curso);
//
//    $this->publicaciones = Doctrine::getTable('PublicacionCurso')
//                        ->createQuery('a')
//                        ->where('a.id_curso = ?',$request->getParameter('id_curso'))
//                        ->execute();
//    $this->entregables = Doctrine::getTable('Entregable')
//                        ->createQuery('e')
//                        ->where('e.id_curso = ?',$request->getParameter('id_curso'))
//                                ->execute();
  }
  public function executeShow(sfWebRequest $request)
  {
      $this->curso = Doctrine::getTable('Curso')->find(array($request->getParameter('id_curso')));
  }
  public function executeNuevaPublicacion(sfWebRequest $request)
  {
//      $this->form = new PublicacioncursoForm();
//      $this->form->getObject()->setIdCurso($request->getParameter('id_curso'));
      $this->form = new NuevaPublicacionForm();
  }
  public function executeNuevoEntregable(sfWebRequest $request)
  {
      $this->form = new EntregableForm();
      $this->id_curso = $request->getParameter('id_curso');
  }
  public function executeEntregables(sfWebRequest $request)
  {
      $this->entregables = Doctrine_Core::getTable('entregable')->findOneBy('id_curso', $request->getParameter('id_curso'));
  }
}
